package com.rxst.msg.base;

import cn.hutool.http.HttpStatus;
import lombok.Data;

/**
 * http 返回的实体类信息
 *
 * @author zhangguoshuai
 */
@Data
public class ResponseVo {

    private static final long serialVersionUID = 1L;
    /**
     * http 状态码
     */
    private Integer code;
    /**
     * http 信息
     */
    private String msg;
    /**
     * http 是否成功
     */
    private boolean success;
    /**
     * http 成功对象
     */
    private Object data;
    /**
     * http 失败对象
     */
    private Object errorData;


    public ResponseVo() {
    }

    public ResponseVo(Integer code, String msg, boolean success) {
        this.code = code;
        this.msg = msg;
        this.success = success;
    }

    public ResponseVo(Integer code, String msg, boolean success, Object data) {
        this.code = code;
        this.msg = msg;
        this.success = success;
        this.data = data;
    }

    public ResponseVo(Integer code, String msg, boolean success, Object data, Object errorData) {
        this.code = code;
        this.msg = msg;
        this.success = success;
        this.data = data;
        this.errorData = errorData;
    }

    /**
     * 成功：默认返回提示信息
     *
     * @return ResponseVo
     */
    public static ResponseVo ok() {
        return new ResponseVo(HttpStatus.HTTP_OK, "操作成功", true);
    }

    /**
     * 成功：返回数据
     *
     * @param object
     * @return
     */
    public static ResponseVo ok(Object object) {
        return new ResponseVo(HttpStatus.HTTP_OK, "操作成功", true, object);
    }

    /**
     * 成功：返回提示信息
     *
     * @param msg
     * @return
     */
    public static ResponseVo ok(String msg) {
        return new ResponseVo(HttpStatus.HTTP_OK, msg, true);
    }

    /**
     * 成功：返回提示信息和数据
     *
     * @param msg
     * @param object
     * @return
     */
    public static ResponseVo ok(String msg, Object object) {
        return new ResponseVo(HttpStatus.HTTP_OK, msg, true, object);
    }

    /**
     * 失败：返回提示信息和数据
     *
     * @return
     */
    public static ResponseVo error() {
        return new ResponseVo(HttpStatus.HTTP_OK, "操作失败", false);
    }


    /**
     * 失败：返回提示信息
     *
     * @param msg
     * @return
     */
    public static ResponseVo error(String msg) {
        return new ResponseVo(HttpStatus.HTTP_OK, msg, false);
    }

    /**
     * 失败：返回提示信息和状态
     *
     * @param msg
     * @return
     */
    public static ResponseVo error(String msg, int code) {
        return new ResponseVo(code, msg, false);
    }

    /**
     * 失败：返回数据
     *
     * @param object
     * @return
     */
    public static ResponseVo error(Object object) {
        return new ResponseVo(HttpStatus.HTTP_OK, "操作失败", false, object);
    }

    /**
     * 失败：返回提示信息和数据
     *
     * @param msg
     * @param object
     * @return
     */
    public static ResponseVo error(String msg, Object object) {
        return new ResponseVo(HttpStatus.HTTP_OK, msg, false, object);
    }

    /**
     * 系统错误：返回提示信息和数据
     *
     * @param msg
     * @return
     */
    public static ResponseVo systemError(String msg) {
        return new ResponseVo(HttpStatus.HTTP_INTERNAL_ERROR, msg, false);
    }

    /**
     * 系统错误：返回提示信息和数据
     *
     * @param msg
     * @param object
     * @return
     */
    public static ResponseVo systemError(String msg, Object object) {
        return new ResponseVo(HttpStatus.HTTP_INTERNAL_ERROR, msg, false, object);
    }

    /**
     * 失败：返回提示信息和数据
     *
     * @param msg
     * @param object
     * @param errorObject
     * @return
     */
    public static ResponseVo error(String msg, Object object, Object errorObject) {
        return new ResponseVo(HttpStatus.HTTP_OK, msg, false, object, errorObject);
    }
}
